<?php
/**
 * DatabaseIterator class
 * To iterate resultsets
 */
namespace PUF;

class DatabaseIterator {
	private $resultset = null;
	
	private $model = null;
	
	private $actualRow = 0;
	
	public function __construct($resultset, $model = null) {
		$this->resultset = $resultset;
		$this->model = $model;
	}
	
	public function hasNext() {
		return $this->actualRow < $this->resultset->num_rows;
	}
	
	public function next() {
		$this->actualRow++;
		if ($this->model) {
			return new $this->model($this->resultset->fetch_assoc());
		} else {
			return $this->resultset->fetch_assoc();
		}
	}
	
	public function setModel($model) {
		$this->model = $model;
	}
}